package com.meirimoney.task;

import java.io.IOException;
import java.util.List;

import android.content.Context;
import android.os.AsyncTask;
import android.view.View;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.ProgressBar;

import com.meiricai.sdk.utility.Common;
import com.meirimoney.adapter.CommodityAdapter;
import com.meirimoney.app.MainActivity;
import com.meirimoney.sdk.models.Commodity;
import com.meirimoney.service.MeiRiMoneyClient;

/***
 * 获取商品列表的任务
 * 
 * @author gewei
 * 
 */
public class CommodityTask extends AsyncTask<Integer, Integer, List<Commodity>> {

	/***
	 * 商品任务的构造函数
	 * 
	 * @param context
	 *            当前执行的上下文
	 * @param list
	 *            list 控件
	 */
	public CommodityTask(Context context, ListView list) {
		this.context = context;
		this.list = list;
	}

	@Override
	protected List<Commodity> doInBackground(Integer... arg0) {
		List<Commodity> commodities = null;
		try {
			commodities = MeiRiMoneyClient.Instance.getCommodities();
		} catch (IOException e) {
			/**
			 * 这里不做任何处理
			 */
		}
		return commodities;
	}

	@Override
	protected void onPostExecute(List<Commodity> result) {
		if (null == result) {
			Common.networkWarn(this.context);
		} else {
			BaseAdapter adapter = new CommodityAdapter(this.context, result);
			this.list.setAdapter(adapter);
		}
	}

	/***
	 * 当前执行上下文
	 */
	private Context context;

	/***
	 * listView对象
	 */
	private ListView list;

}
